/*
 * Userdatabase.h
 *
 *  Created on: Jun 10, 2011
 *      Author: Mario Hock
 */

#ifndef USERDATABASE_H_
#define USERDATABASE_H_

#include "User.h"
#include <map>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>

using boost::property_tree::ptree;
using ariba::NodeID;

class Userdatabase
{
public:
    typedef std::map<string, UserPtr> UserMap;
    typedef std::map<NodeID, UserPtr> IdUserMap;

    
    Userdatabase();
    virtual
    ~Userdatabase();
    
    UserPtr getUser(string name);
    UserPtr getUser(NodeID id);
    UserPtr createUser(string name);
    void insert(UserPtr ptr);
    string list();
    string list_old();
    
    UserPtr createTempUser(ariba::NodeID id);
    bool acceptTempUser(UserPtr tempuser, string name);
    void dropTempUser(UserPtr tempuser);
    
    void set_myself(UserPtr I);
    UserPtr get_myself();
    
    UserMap get_whole_database();
    
    shared_ptr<ptree> save();
    void load(ptree &pt);

private:
    UserMap database;
    IdUserMap id_database;
    UserPtr NO_USER;
    UserPtr myself;
};

#endif /* USERDATABASE_H_ */
